package com.bi.qi;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;



@Order(2)
@Component
@Aspect  //定义切面类
public class AopClass {
    private static final Logger log = LoggerFactory.getLogger(AopClass.class);
    private final ProjectInfoAutoConfiguration projectInfoAutoConfiguration;

    public AopClass(ProjectInfoAutoConfiguration projectInfoAutoConfiguration) {
        this.projectInfoAutoConfiguration = projectInfoAutoConfiguration;
    }

    @Pointcut("@annotation(com.bi.qi.MyAspect)")   //切点（excecution括号的路径是连接点）
    public void pt(){}


    @Around("pt()")     //通知
    public Object recordTime(ProceedingJoinPoint obj) throws Throwable {
        long begin=System.currentTimeMillis();

        Object proceed = obj.proceed();

        long end=System.currentTimeMillis();

        long time=end-begin;



        log.info("AopClass方法耗时：{}",time);

        return proceed;

    }



    @Before("pt()")
    public void before(){
        log.info("AopClass正在执行Before");
    }


    @After("pt()")
    public void after(){
        log.info("AopClass正在执行After");
    }

    @AfterReturning("pt()")
    public void afterReturning(){
        log.info("AopClass正在执行Afterreturning");
    }


    @AfterThrowing("pt()")
    public void throwing(){
        log.info("AopClass连接点有异常抛出");
    }

}
